package com.micangcaihang.micang.mvp.task.model;

import com.micangcaihang.common.baserx.RxSchedulers;
import com.micangcaihang.common.http.ApiResult;
import com.micangcaihang.common.http.RxHelper;
import com.micangcaihang.micang.entity.FTaskCommonBorrowInfoEntity;
import com.micangcaihang.micang.entity.PickerEntity;
import com.micangcaihang.micang.http.ApiService;
import com.micangcaihang.micang.http.FApiService;
import com.micangcaihang.micang.mvp.task.contract.FTaskCommonBorrowInfoContract;

import java.util.List;

import io.reactivex.Observable;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/17
 *     desc   : 风控 共借人信息
 *     version: 1.0
 * </pre>
 */

public class FTaskCommonBorrowInfoModel implements FTaskCommonBorrowInfoContract.Model {
    /**
     * 获取下拉框数据
     *
     * @param type
     * @return
     */
    @Override
    public Observable<ApiResult<List<PickerEntity>>> getPickerViewData(String type) {
        return ApiService.<ApiResult<List<PickerEntity>>>util_choose(type)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    /**
     * 获取共有人信息数据
     *
     * @param id
     * @return
     */
    @Override
    public Observable<ApiResult<List<FTaskCommonBorrowInfoEntity>>> getCommonBorrowInfoData(String id, String customer_type) {
        return FApiService.<ApiResult<List<FTaskCommonBorrowInfoEntity>>>risk_customer(id, customer_type)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    /**
     * 保存信息
     *
     * @param requests
     * @return
     */
    @Override
    public Observable<ApiResult<Void>> savaCommonBorrowInfoData(List<FTaskCommonBorrowInfoEntity> requests, String id) {
        return FApiService.<ApiResult<Void>>risk_save_partner(requests, id)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    /**
     * 删除用户
     *
     * @param customer_id
     * @return
     */
    @Override
    public Observable<ApiResult<Void>> deleteUser(String customer_id) {
        return FApiService.<ApiResult<Void>>risk_delete_customer(customer_id)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }
}
